import streamlit as st

from api.radio.radio_text import generation_to_radio_text

# 首先侧边栏
with st.sidebar:
    st.title("➡️欢迎使用我的AI应用")
    key = st.text_input("请输入通义大模型的密钥：")
    # key获取跳转链接
    st.page_link(
        "https://bailian.console.aliyun.com/?spm=5176.28326591.0.0.40f76ee1vUR5Of&accounttraceid=d873c9fe82ea443d9f3170f30dd5690cfnng#/api_key",
        label="无key？请点我获取", icon="🌎")

st.title("🌎视频文本生成器")
subject = st.text_input("请输入你的视频主题:")
time = st.number_input("请输入你的视频时长，单位为分钟",step=1.0,min_value=0.5,max_value=60.0,value=1.0)
temperature = st.slider("请调整文本生成随机性",min_value=0.0,max_value=1.0,step=0.1,value=0.5)

flag = st.button("生成")
if flag :
    if not key:
        st.info("请输入大模型密钥")
        st.stop()
    if not subject:
        st.info("请输入主题")
        st.stop()
    if not time:
        st.info("请输入视频时长")
        st.stop()
    with st.spinner("AI正在思考，请稍等"):
        search_content, title_context, script_context = generation_to_radio_text(key,temperature,subject,time)
        st.divider()
        st.subheader("标题："+title_context)
        st.write("内容:\n"+script_context)
        with st.expander("查看参考文本"):
            st.write(search_content)


